package main

import "fmt"

func sender(ch chan<- int) {
    for i := 0; i < 10; i++ {
		fmt.Println("发送方发送值:", i)
		ch <- i
	}
	fmt.Println("发送完毕，关闭通道...")
	close(ch)
}

func reveiver(ch <-chan int) {
	for {
		elem, ok := <- ch
		if !ok {
			fmt.Println("感知到通道已经关闭")
			break
		}
		fmt.Println("接收方接收值:", elem)
	}
}

func main() {
	intChan := make(chan int, 2)
	// 发送方
	go sender(intChan)
	// 接收方
	reveiver(intChan)
	fmt.Println("结束...")
}